package m.jclecai.com.activity.follow;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.IdRes;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;

import com.bumptech.glide.Glide;
import com.handmark.pulltorefresh.library.MyListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.squareup.okhttp.Request;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.activity.LotteryJCLQActivity;
import m.jclecai.com.activity.LotteryJCZQActivity;
import m.jclecai.com.adapter.OrderFollowPeopleAdapter;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.bean.ProofBean;
import m.jclecai.com.bean.Response.ResFollowOrederPeopleList;
import m.jclecai.com.bean.Response.ResHotOrederDetail;
import m.jclecai.com.bean.UserBean;
import m.jclecai.com.constant.Constant_Url;
import m.jclecai.com.utils.PreferenceUtil;
import m.jclecai.com.utils.ScreenUtil;
import m.jclecai.com.utils.ToastUtil;
import m.jclecai.com.utils.http.FastOk;
import m.jclecai.com.utils.http.HttpManager;
import m.jclecai.com.view.common.AddDelEditTextView;

/**
 * Created by Dinosa on 2017/11/17.
 * 跟单详情
 */

public class HotOrderDetailActivity extends BaseActivity implements PullToRefreshBase.OnRefreshListener2 {


    @BindView(R.id.iv_user_icon)
    ImageView mIvUserIcon;

    @BindView(R.id.tv_username)
    TextView mTvUsername;

    @BindView(R.id.tv_follow)
    TextView mTvFollow;

    @BindView(R.id.tv_win_total_money)
    TextView mTvWinTotalMoney;

    @BindView(R.id.tv_unit_award)
    TextView mTvUnitAward;

    @BindView(R.id.tv_lottery_name)
    TextView mTvLotteryName;

    @BindView(R.id.tv_expected_report)
    TextView mTvExpectedReport;

    @BindView(R.id.tv_desc)
    TextView mTvDesc;

    @BindView(R.id.tv_one_money)
    TextView mTvOneMoney;

    @BindView(R.id.tv_follow_money)
    TextView mTvFollowMoney;

    @BindView(R.id.tv_min_money)
    TextView mTvMinMoney;

    @BindView(R.id.tv_order_number)
    TextView mTvOrderNumber;

    @BindView(R.id.tv_create_time)
    TextView mTvCreateTime;

    @BindView(R.id.btn_follow_order_detail_go_on)
    Button btn_follow_order_detail_go_on;

//    @BindView(R.id.tl_tablayout)
//    TabLayout mTlTablayout;

//    @BindView(R.id.vp_view_pager)
//    ViewPager mVpViewPager;

    @BindView(R.id.rb_10)
    RadioButton mRb10;

    @BindView(R.id.rb_20)
    RadioButton mRb20;

    @BindView(R.id.rb_50)
    RadioButton mRb50;

    @BindView(R.id.rb_100)
    RadioButton mRb100;

    @BindView(R.id.rg_group)
    RadioGroup mRgGroup;

    @BindView(R.id.tv_bet_total_money)
    TextView mTvBetTotalMoney;

    @BindView(R.id.tv_bet)
    TextView mTvBet;

    @BindView(R.id.tv_play_mode)
    TextView mTvPlayMode;

    @BindView(R.id.ll_follow_container)
    LinearLayout mLlFollowContainer;

    @BindView(R.id.addAndDelView)
    AddDelEditTextView mAddDelEditTextView;


    @BindView(R.id.tv_award_number)
    TextView mTvAwardNumber;

    @BindView(R.id.rl_award_bg)
    RelativeLayout mRlAwardBg;

//    @BindView(R.id.tv_title)
//    TextView mTvTitle;

//    @BindView(R.id.tv_end_time)
//    TextView mTvEndTime;

    @BindView(R.id.table)
    TableLayout mTableLayout;

    @BindView(R.id.tv_content)
    TextView mTvContent;

    @BindView(R.id.tv_bet_lock_dec)
    TextView mTvBetLockDec;

    @BindView(R.id.ll_last)
    View mViewLast;

    @BindView(R.id.rlLock)
    View rlLock;
    public static final String ORDER_ID = "orderId";

    @BindView(R.id.tv_title)
    TextView mTvTitle;

    @BindView(R.id.ll_item)
    LinearLayout mLlItem;

    @BindView(R.id.ptr_listView)
    MyListView mPtrListView;

    @BindView(R.id.fl_content)
    LinearLayout mFlContent;

    @BindView(R.id.tv_group_buy_money)
    TextView tv_group_buy_money;

    @BindView(R.id.tv_status)
    TextView tv_status;

    @BindView(R.id.tv_jiangjin)
    TextView tv_jiangjin;

    int mPage = 1;
//    @BindView(R.id.fl_empty)
//    LinearLayout mFlEmpty;

    @BindView(R.id.pull_to_refresh_scrollView)
    PullToRefreshScrollView pull_to_refresh_scrollView;
    @BindView(R.id.tv_follow_detail_project_times)
    TextView tv_follow_detail_project_times;

    @BindView(R.id.tv_follow_detail_project_mode)
    TextView tv_follow_detail_project_mode;

    @BindView(R.id.tv_follow_detail_project_beishu)
    TextView tv_follow_detail_project_beishu;

    @BindView(R.id.tv_follow_beizhu)
    TextView tv_follow_beizhu;

    private OrderFollowPeopleAdapter mHotPeopleListAdapter;

//    public String[] pagerTitles = {"方案详情"};

//    private HotOrderViewPagerAdapter mHotOrderViewPagerAdapter;
//    private ArrayList<BaseFragment> mBaseFragments;
//    private HotOrderDetailFragment mHotOrderDetailFragment;
//    private HotOrderPeopleFragment mHotOrderPeopleFragment;

    private String mPlanId;
    private int mCurBetNumber;
    private ResHotOrederDetail mOrederDetail;
    private int beishu;
    private ResHotOrederDetail mHotOrederDetail;
    private String mFollowOrderId;
    private List<ResFollowOrederPeopleList.FollowPeopleBean> arrayList;
    private int totalPages;
    private boolean isNeedLoadMore = true;


    @Override
    protected int getContentView() {
        return R.layout.activity_follow_order_detail;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("跟单详情");
        beishu = getIntent().getIntExtra("beishu", 1);
        initCheckStatus();
        mAddDelEditTextView.setBetNumber(beishu);
        leftOptionText("");
    }

    private void initCheckStatus() {
        for (int i = 0; i < mRgGroup.getChildCount(); i++) {
            RadioButton radioButton = (RadioButton) mRgGroup.getChildAt(i);
            if (Integer.valueOf(radioButton.getTag().toString()) == beishu) {
                ((RadioButton) mRgGroup.getChildAt(i)).setChecked(true);
                break;
            }
        }
    }

    @OnClick(R.id.tv_follow)
    public void onClickFollow(View view) {
        //这里我们要切换关注与取消关注；
        String s = mTvFollow.getText().toString();
        if ("已关注".equals(s)) {
            doFollowRequest("del");
        } else {
            //取消关注
            doFollowRequest("add");
        }

    }

    private void doFollowRequest(String operation) {
        final HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("user", PreferenceUtil.getUserName(this));
        paramsMap.put("password", PreferenceUtil.getPassword(this));
        paramsMap.put("type", operation);
        paramsMap.put("id", mResHotOrderDetail.getUser_id());

        HttpManager.postAsyn(Constant_Url.FOLLOW_HOT_PEOPLE, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                dissDialog();
                DisPlay("网络异常");
            }

            @Override
            public void onResponse(String response) {
                dissDialog();
                if (!TextUtils.isEmpty(response)) {

                    ProofBean proofBean = FastOk.get(response, ProofBean.class);
                    if ("0".equals(proofBean.getStatus())) {
                        DisPlay(proofBean.getMessage());
                        String followStatue = mTvFollow.getText().toString().equals("已关注") ? "+ 关注" : "已关注";
                        mTvFollow.setText(followStatue);
                    } else {
                        DisPlay(proofBean.getMessage());
                    }
                } else {
                    DisPlay("网络异常!!!");
                }
            }
        }, paramsMap);
    }

    @Override
    protected void initData() {
        super.initData();
        //这里我们要做的一个操作就是显示初始化数据；

//        mBaseFragments = new ArrayList<>();
//        mHotOrderDetailFragment = new HotOrderDetailFragment();
//        mHotOrderPeopleFragment = new HotOrderPeopleFragment();
//
////        mBaseFragments.add(mHotOrderDetailFragment);
//        mBaseFragments.add(mHotOrderPeopleFragment);

//        mHotOrderViewPagerAdapter = new HotOrderViewPagerAdapter(getSupportFragmentManager());
//        mVpViewPager.setAdapter(mHotOrderViewPagerAdapter);
//        mTlTablayout.setupWithViewPager(mVpViewPager);
        arrayList = new ArrayList<>();
        mHotPeopleListAdapter = new OrderFollowPeopleAdapter(this, arrayList);
        mPtrListView.setAdapter(mHotPeopleListAdapter);

        pull_to_refresh_scrollView.setMode(PullToRefreshBase.Mode.BOTH);
        pull_to_refresh_scrollView.setOnRefreshListener(this);

        mPlanId = getIntent().getStringExtra(ORDER_ID);
        requestOrderDetail(mPlanId);
    }

    private ResHotOrederDetail mResHotOrderDetail;

    private void requestOrderDetail(String planId) {

        showDialog();
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("id", planId);
        paramsMap.put("user", PreferenceUtil.getUserName(this));

        HttpManager.postAsyn(Constant_Url.HOT_ORDER_DETAIL, new HttpManager.StringCallback() {

            @Override
            public void onFailure(Request request, IOException e) {

                dissDialog();
                DisPlay("网络异常!!!");
            }

            @Override
            public void onResponse(String response) {
                dissDialog();
                try {
                    if (!TextUtils.isEmpty(response)) {
                        mResHotOrderDetail = FastOk.get(response, ResHotOrederDetail.class);
                        if (mResHotOrderDetail != null) {
                            if ("0".equals(mResHotOrderDetail.getStatus())) {
                                updateUI(mResHotOrderDetail);
                            } else {
                                DisPlay(mResHotOrderDetail.getMessage());
                            }
                        } else {
                            DisPlay("网络异常!!");
                        }
                    } else {
                        DisPlay("网络异常!!");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    DisPlay("网络异常!!");
                }

            }
        }, paramsMap);

    }


    /**
     * 刷新界面；
     *
     * @param orederDetail
     */
    private void updateUI(final ResHotOrederDetail orederDetail) {


        mOrederDetail = orederDetail;

        if (orederDetail.getState().equals("1")) {

            mTvAwardNumber.setVisibility(View.INVISIBLE);
            mRlAwardBg.setBackgroundResource(R.drawable.follow_no_win_img);
            mRlAwardBg.setVisibility(View.VISIBLE);

        } else if (orederDetail.getState().equals("2")) {


            mTvAwardNumber.setVisibility(View.INVISIBLE);
            mRlAwardBg.setVisibility(View.VISIBLE);
            mRlAwardBg.setBackgroundResource(R.drawable.follow_no_win_img);

        } else if (orederDetail.getState().equals("3")) {


            mTvAwardNumber.setVisibility(View.VISIBLE);
            mTvAwardNumber.setText("￥" + orederDetail.getWin_money());
            mRlAwardBg.setVisibility(View.VISIBLE);
            mRlAwardBg.setBackgroundResource(R.drawable.follow_win);

        } else {
            mRlAwardBg.setVisibility(View.INVISIBLE);
        }

//        mTvUnitAward.setText("7日盈利率: " + orederDetail.getPayback());
        mTvExpectedReport.setText("预计回报：" + orederDetail.getReturnrate() + "倍");


        //用户信息
        mTvUsername.setText(orederDetail.getUsername());
        Glide.with(this)
                .load(orederDetail.getUser_face())
                .into(mIvUserIcon);
        mTvUnitAward.setText(orederDetail.endtime + "截止");//截止时间
        mTvUnitAward.setVisibility(View.VISIBLE);
        mTvPlayMode.setText(orederDetail.getMilitary_total().replace("/", "中"));
        if ("1".equals(orederDetail.getAttention())) {
            //这里表示已经关注了
            mTvFollow.setText("已关注");
        } else {
            mTvFollow.setText("+ 关注");
        }
        mAddDelEditTextView.setBetNumber(beishu);
        mTvBetTotalMoney.setText("共" + Float.parseFloat(orederDetail.getFollow_minmoney()) * beishu + "元");

        if (orederDetail.getCan_follow() > 0) {
            //这里表示可以跟单；
            mLlFollowContainer.setVisibility(View.VISIBLE);
        } else {
            mLlFollowContainer.setVisibility(View.GONE);
        }
        tv_group_buy_money.setText(orederDetail.getOne_money() + "元");//方案金额
        //方案状态
        tv_status.setText(orederDetail.getState_desc() + "");
        //status(int : 2未中奖 ，3已中奖【还要判断opencode:0未派奖，1已派奖】 ， 其他待开奖 )
        //加奖奖金
        tv_jiangjin.setText(orederDetail.getWin_money() + "元");
        //备注
        tv_follow_beizhu.setText(orederDetail.getTitle());

        String method = orederDetail.getMethodname().replace("*", "串");
        //跟单描述
        mTvLotteryName.setText(orederDetail.getLotteryname() + "  " + method);
        mTvDesc.setText(orederDetail.getTitle());

//        mTvOneMoney.setText("自购:    " + orederDetail.getOne_money());
        mTvFollowMoney.setText("跟单:    " + orederDetail.getFollow_money());
        //
        mTvMinMoney.setText(orederDetail.getFollow_minmoney() + "元起投");

        mTvOrderNumber.setText(orederDetail.getProjectno());
        mTvCreateTime.setText(orederDetail.getAddtime());
        btn_follow_order_detail_go_on.setText("继续购买" + orederDetail.getLotteryname());
        btn_follow_order_detail_go_on.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //继续购买
                switch (orederDetail.getClassid()) {
                    case 5:
                        //足球
                        startActivity(new Intent(HotOrderDetailActivity.this, LotteryJCZQActivity.class));
                        break;
                    case 6:
                        startActivity(new Intent(HotOrderDetailActivity.this, LotteryJCLQActivity.class));
                        //蓝球
                        break;
                }
            }
        });
        //这里我们要对Fragment进行一个赋值操作；
//        pagerTitles[1] = "跟单用户" + "(" + orederDetail.getFollow_count() + ")";
        updateUICaseDetail(orederDetail);//方案详情
        updateUIFollowList(orederDetail, mPlanId);

//        mHotOrderViewPagerAdapter.notifyDataSetChanged();

    }

    /**
     * 更新页面
     *
     * @param hotOrederDetail 这几串几，我们是不知道的所以这里我们是需要这样写的；
     */
    public void updateUICaseDetail(ResHotOrederDetail hotOrederDetail) {


//        mTvTitle.setText("过关方式: " + hotOrederDetail.getMethodname().replace("*", "串"));

//        mTvEndTime.setText("截止时间: " + hotOrederDetail.getEndtime());
        mHotOrederDetail = hotOrederDetail;

//        if (mHotOrederDetail.getOflag() == 2) {
//            mViewLast.setVisibility(View.VISIBLE);
//            mTvContent.setVisibility(View.GONE);
//            //这里我们是需要判断一下是否只有一个条目，如果只有一个条目我们就隐藏内容；
//            if (mHotOrederDetail.getMatchorder().size()==1) {
//                mTvBetLockDec.setVisibility(View.GONE);
//            }else {
//                mTvBetLockDec.setVisibility(View.VISIBLE);
//            }
//        }else{
//            mViewLast.setVisibility(View.GONE);
//
//        }
        //场数
        tv_follow_detail_project_times.setText(mHotOrederDetail.getMatchorder().size() + "场");
        //投注方式
        tv_follow_detail_project_mode.setText(hotOrederDetail.getMethodname().replace("*", "串"));
        //截止时间

        //倍数
        tv_follow_detail_project_beishu.setText(mHotOrederDetail.getMultiple() + "倍");
        updateTable(hotOrederDetail);
    }

    /**
     * 这里我们用来更新表格里面的内容；
     */
    private void updateTable(ResHotOrederDetail hotOrederDetail) {
        int height = 0;
        int top = 0;
        int splitHeight = ScreenUtil.dip2px(this, 1);
        for (int i = 0; i < mHotOrederDetail.getMatchorder().size(); i++) {
            ResHotOrederDetail.MatchorderBean matchorderBean = mHotOrederDetail.getMatchorder().get(i);
            View inflate = LayoutInflater.from(this).inflate(R.layout.table_row_layout, mTableLayout, false);
            mTableLayout.addView(inflate);

            TextView one = (TextView) inflate.findViewById(R.id.tv_one);
            TextView two = (TextView) inflate.findViewById(R.id.tv_two);
            TextView three = (TextView) inflate.findViewById(R.id.tv_three);
            TextView four = (TextView) inflate.findViewById(R.id.tv_four);
            TextView five = (TextView) inflate.findViewById(R.id.tv_five);

            one.setText(getOneText(matchorderBean));
            two.setText(Html.fromHtml(getTwoText(matchorderBean)));
            three.setText(Html.fromHtml(getThreeText(matchorderBean)));
            four.setText(Html.fromHtml(getFourText(matchorderBean)));
            one.measure(0,
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            //根据score有无值来判断是否显示开奖  matchSelect显示开奖数据

            Log.e("==canWatch==", isCanWatch(hotOrederDetail) + "");
            if (isCanWatch(hotOrederDetail)) {
                five.setVisibility(View.VISIBLE);
                five.setText(Html.fromHtml(getFiveText(matchorderBean)));
                top += one.getMeasuredHeight() + splitHeight;
            } else {
                five.setVisibility(View.INVISIBLE);
            }
//            View.inflate(getActivity(),R.layout.table_row_line_layout,mTableLayout);
            height += one.getMeasuredHeight() + splitHeight;
        }

        //这里控制覆盖在开奖信息上的锁的位置大小


        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) rlLock.getLayoutParams();
        layoutParams.topMargin = top;
        layoutParams.height = height - top;
        rlLock.setLayoutParams(layoutParams);
        if (isSecret)
            mTvBetLockDec.setText("保密单");
        else
            mTvBetLockDec.setText("截止后公开");
        if (top == height)
            rlLock.setVisibility(View.GONE);
    }

    private boolean isSecret = false;

    /**
     * 这里表示是否可以看到保密；
     *
     * @return
     */
    public boolean isCanWatch(ResHotOrederDetail hotOrederDetail) {
        //
        if (hotOrederDetail.getOflag() == 0) {
            //公开；
            return true;
        } else if (hotOrederDetail.getOflag() == 1) {
            //截止后公开
            String endtime = hotOrederDetail.getEndtime();
            Date parse = null;
            try {
                parse = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endtime);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            Date date = new Date();

            //这里表示截至时间已经开始了；
            if (parse.getTime() < date.getTime()) {

                return true;
            } else {
                return false;
            }

        } else {
            //这里表示保密；
            UserBean userBean = PreferenceUtil.readUser(this);
            if (userBean == null) {

                return false;

            } else {
                //判断是不是自己，已经跟单里面有没有自己；

                String user_id = hotOrederDetail.getUser_id();
                List<String> follow_users = hotOrederDetail.getFollow_users();

                if (userBean.getUser_id().equals(user_id)) {
                    isSecret = false;
                    return true;
                }

                if (follow_users != null && follow_users.size() > 0) {
                    boolean contains = follow_users.contains(userBean.getUser_id());
                    if (contains)
                        isSecret = false;
                    else
                        isSecret = true;

                    return contains;
                }

            }


        }

        return false;
    }

    //这里是场次的数据源
    private String getOneText(ResHotOrederDetail.MatchorderBean bean) {

        return weekIntToStr(bean.getWeek()) + "\n" + getTerm(bean.getId());

    }

    //主队
    private String getTwoText(ResHotOrederDetail.MatchorderBean bean) {
        //这里我们做一个操作：
        if (!TextUtils.isEmpty(bean.getBall())) {

            //这里表示有让球的概念：
            double integer = 0;
            try {
                integer = Double.parseDouble(bean.getBall());
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            if (integer >= 0) {

                return bean.getHome() + "<br/>" + createHtml("(" + bean.getBall() + ")", "red");
            } else if (integer < 0) {

                return bean.getHome() + "<br/>" + createHtml("(" + bean.getBall() + ")", "#003300");
            }
        }
        return bean.getHome();
    }

    //比分
    private String getThreeText(ResHotOrederDetail.MatchorderBean bean) {

        String socre = "";
        if (!TextUtils.isEmpty(bean.getHscore())) {
            socre += bean.getHscore();
        }
        if (!TextUtils.isEmpty(bean.getScore())) {
            if (!TextUtils.isEmpty(socre)) {
                socre += "\n";
            }
            socre += bean.getScore();
        }

        return socre;
    }

    //客队
    private String getFourText(ResHotOrederDetail.MatchorderBean bean) {
        return bean.getVisit();
    }

    //投注内容
    private String getFiveText(ResHotOrederDetail.MatchorderBean bean) {
        //这里是投注内容的部分；
        String content = "";
        //这里我们要设置
        for (int i = 0; i < bean.getMatchSelect().size(); i++) {

            boolean isAward = false;
            String result = bean.getMatchResult().get(i);

            result = result.split("\\(")[0];

            String select = bean.getMatchSelect().get(i);
            select = select.split("\\(")[0];

            if (result.equals(select) && !TextUtils.isEmpty(result)) {
                isAward = true;
            }

            String color = isAward ? "red" : "gray";
            content += createHtml(bean.getMatchSelect().get(i), color);
            if (i < bean.getMatchSelect().size() - 1) {
                content += "<br/>";
            }
        }
        return content;
    }


    public String createHtml(String content, String color) {
        return "<html><font color='" + color + "'>" + content + "</font></html>";
    }

    /**
     * 将1，2，3，..转换对应的周日；
     *
     * @return
     */
    public String weekIntToStr(String week) {
        switch (week) {
            case "1":
                return "周一";
            case "2":
                return "周二";
            case "3":
                return "周三";
            case "4":
                return "周四";
            case "5":
                return "周五";
            case "6":
                return "周六";
            case "7":
                return "周日";
        }
        return "周一";
    }

    /**
     * 获取期号
     *
     * @return
     */
    public String getTerm(String term) {

        if (term.length() > 3) {
            return term.substring(term.length() - 3);
        } else {
            return term;
        }
    }

    @Override
    protected void initListener() {
        super.initListener();

        mRgGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId) {
                    case R.id.rb_10:
                        mAddDelEditTextView.setBetNumber(10);
                        break;
                    case R.id.rb_20:
                        mAddDelEditTextView.setBetNumber(20);
                        break;
                    case R.id.rb_50:
                        mAddDelEditTextView.setBetNumber(50);
                        break;
                    case R.id.rb_100:
                        mAddDelEditTextView.setBetNumber(100);
                        break;
                }
            }
        });


        mAddDelEditTextView.setOnBetNumberChangeListener(new AddDelEditTextView.OnBetNumberChangeListener() {

            @Override
            public void onBetNumberChange(int betNumber) {

                mCurBetNumber = betNumber;
                //这里我们做的操作
                if (betNumber == 10) {
                    mRb10.setChecked(true);
                } else if (betNumber == 20) {
                    mRb20.setChecked(true);
                } else if (betNumber == 50) {
                    mRb50.setChecked(true);
                } else if (betNumber == 100) {
                    mRb100.setChecked(true);
                }
                //这里我们同时是需要刷新金额的；
                int needMoney = 0;
                try {
                    if (!TextUtils.isEmpty(mOrederDetail.getFollow_minmoney()))
                        needMoney = betNumber * Integer.parseInt(mOrederDetail.getFollow_minmoney());
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
                mTvBetTotalMoney.setText("共" + needMoney + "元");
            }
        });

        mTvBet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //这里我们要做的一个操作就是跳转到投注的页面

                if (mResHotOrderDetail == null) {
                    return;
                }

                String lotteryName = mResHotOrderDetail.getLotteryname();
                int totalMoney = Integer.parseInt(mResHotOrderDetail.getFollow_minmoney()) * mCurBetNumber;

                Intent intent = FollowOrderConfirmActivity.getIntent(HotOrderDetailActivity.this, mPlanId, mCurBetNumber + "", lotteryName, totalMoney + "");
                startActivity(intent);
            }
        });
    }


    public static Intent getIntent(Context context, String orderId) {
        Intent intent = new Intent(context, HotOrderDetailActivity.class);
        intent.putExtra(ORDER_ID, orderId);
        return intent;
    }


    //更新用户列表

    /**
     * 更新页面
     *
     * @param hotOrederDetail 这几串几，我们是不知道的所以这里我们是需要这样写的；
     */
    public void updateUIFollowList(ResHotOrederDetail hotOrederDetail, String orderId) {

        mFollowOrderId = orderId;

//        String html = "当前跟单<html><font color='red'>" + hotOrederDetail.getFollow_count() + "</font></html>人 , " +
//                "跟单金额<html><nt color='red'>" + hotOrederDetail.getFollow_money() + "</font></html>元";
        String html = "跟单列表(" + hotOrederDetail.getFollow_count() + "人 , " +
                "跟单金额:" + hotOrederDetail.getFollow_money() + "元)";


        mTvTitle.setText(Html.fromHtml(html));

        if (Integer.parseInt(hotOrederDetail.getFollow_count()) > 0) {
            mFlContent.setVisibility(View.VISIBLE);
//            mFlEmpty.setVisibility(View.INVISIBLE);
            requestData();
        } else {
            //这里表示没有跟单的列表
            mFlContent.setVisibility(View.INVISIBLE);
//            mFlEmpty.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase refreshView) {
        mPage = 1;
        arrayList.clear();
        requestData();
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase refreshView) {
        requestData();
    }


    public void requestData() {
        if (!isNeedLoadMore) {
            pull_to_refresh_scrollView.onRefreshComplete();
            return;
        }
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("id", mFollowOrderId + "");    //订单id;
        paramsMap.put("page", mPage + "");
        //这里我们是需要订单id
        HttpManager.postAsyn(Constant_Url.FOLLOW_ORDER_PEOPLE_LIST, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                ToastUtil.showToast(HotOrderDetailActivity.this, "网络连接异常!!!");
                pull_to_refresh_scrollView.onRefreshComplete();
            }

            @Override
            public void onResponse(String response) {
                pull_to_refresh_scrollView.onRefreshComplete();
                if (!TextUtils.isEmpty(response)) {
                    ResFollowOrederPeopleList resHotPeople = FastOk.get(response, ResFollowOrederPeopleList.class);
                    if (resHotPeople != null) {
                        if ("0".equals(resHotPeople.getStatus())) {
                            totalPages = Integer.parseInt(resHotPeople.getPages());
                            if (mPage == 1) {
                                mHotPeopleListAdapter.clear();
                            }
                            if (mPage < totalPages) {
                                mPage += 1;
                                mHotPeopleListAdapter.addAll(resHotPeople.getRecords());
                            } else {
                                if (isNeedLoadMore) {
                                    isNeedLoadMore = false;
                                    mHotPeopleListAdapter.addAll(resHotPeople.getRecords());
                                } else {

                                }
                            }
//                            if (mPage <= totalPages&&isNeedLoadMore) {
//                            }
//                            if (mPage>=totalPages) {
//                                isNeedLoadMore = false;
//                            }

                        } else {
                            DisPlay(resHotPeople.getMessage());
                        }
                    } else {
                        DisPlay("网络异常!!!");
                    }
                } else {
                    DisPlay("网络异常!!!");
                }
            }
        }, paramsMap);
    }

}
